package com.test.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.dao.AdminuserDao;
import com.test.entity.Adminuser;
import com.test.service.AdminuserService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminuserServiceImpl implements AdminuserService {

    @Resource
    AdminuserDao adminuserDao;

    @Override
    public Adminuser getAdminUser(Adminuser adminuser) {
        String psw = DigestUtils.md5DigestAsHex(adminuser.getPassword().getBytes());
        System.out.println(psw);
        adminuser.setPassword(psw);
        return adminuserDao.getAdminUser(adminuser);
    }

    @Override
    public PageInfo<Adminuser> queryByPage(Adminuser adminuser, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Adminuser> usersList = adminuserDao.queryAll(adminuser);
        PageInfo<Adminuser> pageInfo = new PageInfo<>(usersList);
        return pageInfo;
    }

    @Override
    public boolean deleteById(int id) {
        return this.adminuserDao.deleteById(id) > 0;
    }

    @Override
    public Adminuser getUserInfo(Adminuser adminuser) {
        Adminuser adminUser = adminuserDao.getAdminUser(adminuser);
        return adminUser;
    }
}
